<div class="box_right">
	<h1>
		订单统计
		
	</h1>
	<div class="pro_box">
			<div class="line">
				<ul class="layui-row">
					<li class="lf active">
						<b><?php echo $date_1;?></b>
						<p>当日销售金额（元）</p>
					</li>
					<li class="cet">
						<b><?php echo $date_2;?></b>
						<p>当日销售笔数（单）</p>
					</li>
					<li class="rt">
						<b><?php echo $date_3;?></b>
						<p>当日人均消费（元）</p>
					</li>
				</ul>
				<div id="main_time" style="height: 500px;">
					
				</div>
			</div>
			  <br>
			  <div class="order_list">
			  	<div class="layui-row">
			  		<div class="layui-col-xs4">
			  			<h2 class="order_list_h">订单列表</h2>
			  		</div>
			  		<div class="layui-col-xs1 layui-col-xs-offset7">
        	  			<?php if (isset($result)&&count($result)>0){?>
        	  			<a class="btn_get" href="<?php echo base_url().'gasstation/index/order_excel';?>">导出</a>
        	  			<?php }else{?>
        	  			<a class="btn_get" href="#" onclick="show_content()">导出</a>
        	  			<?php }?>
        	  		<a href="javascript:void(0)" onclick="socket()" data-toggle="modal" class="btn btn_get" style="background: #F18101;">socket</a>
        	  		</div>
			  	</div>
			  		
				
		<table class="layui-table" lay-skin="line">
		  <thead>
		    <tr>
			  <th>订单号</th>
			  <th>时间</th>
			  <th>车牌号</th>
			  <th>油枪/商品</th>
			  <th>付款方式</th>
			  <th>加油金额</th>
			  <th>折后金额</th>
			  <th>发票金额</th>
			  <th>操作</th>
			  
		    </tr> 
		  </thead>
		  <tbody>
		    <?php if (isset($result)&&count($result)>0){
					foreach ($result as $app){
			?>
			<tr>
				<td><?php echo $app->order_no;?></td>
				<td><?php echo $app->create_time;?></td>
				<td><?php echo $app->car_card;?></td>
				<td><?php echo $app->oilgun_name.'/'.$app->glmodel_name;?></td>
				<td><?php
                    if(!empty($app->from_third)){
						echo '第三方平台支付';
					}elseif($app->payment_id == 2){
                        echo "支付宝支付";
                    }elseif($app->payment_id == 3){
                    	echo "微信公众号支付";
                    }elseif($app->payment_id == 6){
                    	echo "支付宝APP支付";
					}elseif($app->payment_id == 7){
                    	echo "微信APP支付";
					}elseif($app->payment_id == 8){
                    	echo "钱包支付";
					}elseif($app->payment_id == 9){
						echo "小程序支付";
					}
					?>
				</td>
				<td><?php echo sprintf("%.2f", $app->machine_price);?></td>
				<td>
                   <?php if (round($app->machine_price-($app->yz_before_price-$app->yz_price)*$app->oil_liters,2) > $app->machine_price) {?>
                   <?php echo sprintf("%.2f", $app->machine_price);?>
                   <?php }else{?>
                   <?php echo sprintf("%.2f", $app->machine_price-($app->yz_before_price-$app->yz_price)*$app->oil_liters) ;?>
                   <?php }?>
				</td>
				<td>
				<?php if ($app->is_issue == 1){?>
				
                   <?php if (round($app->machine_price-($app->yz_before_price-$app->yz_price)*$app->oil_liters,2) > $app->machine_price) {?>
                   <?php echo sprintf("%.2f", $app->machine_price);?>
                   <?php }else{?>
                   <?php echo sprintf("%.2f", $app->machine_price-($app->yz_before_price-$app->yz_price)*$app->oil_liters) ;?>
                   <?php }?>
				
				<?php }else{?>0
				<?php }?>
				</td>
				<td>
				<?php if ($app->settlement_state == 0){?>
				<a href="javascript:void(0)" onclick="cancelmodal('<?php echo $app->id;?>')" data-toggle="modal" class="btn btn-danger btn-sm">退款</a>
				<?php }elseif ($app->settlement_state == 1){?>
				<a class="btn btn-danger btn-sm" style="background: #DBDBDB;border-color:#DBDBDB">已结算</a>
				<?php }elseif ($app->settlement_state == 2){?>
				<a class="btn btn-danger btn-sm" style="background: #DBDBDB;border-color:#DBDBDB">已冻结</a>
				<?php }elseif ($app->settlement_state == 3){?>
				<a class="btn btn-danger btn-sm" style="background: #DBDBDB;border-color:#DBDBDB">已退款</a>
				<?php }?>
				<a class="btn btn-danger btn-sm" href="<?php echo base_url().'gasstation/index/print_invoice_get/'.$app->id;?>" style="background: #DBDBDB;border-color:#DBDBDB">重新打印</a>
				</td>
			</tr>
				<?php }
			}else{?>
			<tr>
				<td colspan="15">无数据</td>
			</tr>
			<?php }?>
		  </tbody>
		</table>		
	</div> 
	</div>
</div>

<div id="cancelModal" class="modal fade" role="dialog" aria-hidden="true">
	<div class="modal-dialog" style="width: 300px">
		<div class="modal-content">
			<div class="modal-header">
			  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			  <h3>提示信息</h3>
			</div>
			<div class="modal-body">
			  <p>订单进行退款后将无法恢复，已支付的金额会直接退回用户支付账户<br>确定要退款吗？</p>
			</div>
			<div class="modal-footer">
			  <input type="hidden" id="cancel_order_id" value="">
			  <a id="cancelbtn" href="#" onclick="cancel()" class="btn btn-danger">确定</a>
			  <a href="#" class="btn btn-info" data-dismiss="modal" aria-hidden="true">取消</a>
			</div>
		</div>
	</div>
</div>

<script src="<?php echo base_url()?>themes/gasstation/js/echarts.min.js"></script>
<script>
//Demo
layui.use(['form','element'], function(){
  var form = layui.form,
  	element = layui.element;
  
  //监听提交
  form.on('submit(formDemo)', function(data){
    layer.msg(JSON.stringify(data.field));
    return false;
  });
});

//初始化
// 基于准备好的dom，初始化echarts实例
var myChart = echarts.init(document.getElementById('main_time'));

  var data=

option = {
    title: {
        text: ''
    },
    tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    legend: {
        data:['近24小时','上24小时'],
        bottom: 10,
        left: 'center',
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '15%',
        containLabel: true
    },
    xAxis : [
        {
            type : 'category',
            data : ['0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23']
        }
    ],
    yAxis : [
        {
            type : 'value'
        }
    ],
    series : []
};

 myChart.setOption(option);   //参数设置方法
 $.post('<?php echo base_url() . 'gasstation/index/getEchartsInfo' ?>',{gasstation_id:<?php echo $gasstation_id ?>},function(res){

var res = JSON.parse(res);

if(res.status == 1){
	var info = res;
	data1=[ {name:'近24小时',type:'line',data:info.now_day.new_total},{name:'上24小时',type:'line',data:info.yesterday.new_total}];
	data2=[ {name:'近24小时',type:'line',data:info.now_day.new_count},{name:'上24小时',type:'line',data:info.yesterday.new_count}];
	data3=[ {name:'近24小时',type:'line',data:info.now_day.consumption_per_hour},{name:'上24小时',type:'line',data:info.yesterday.consumption_per_hour}];
	//默认加载当日销售金额
	 myChart.setOption({ series:data1});
 }else{
	 console.log(res.msg);
 }

})     
 
window.onresize = function () {

    myChart.resize();
}; 

//默认加载当日销售金额
 myChart.setOption({ series:data1});

$(".line .lf").click(function(){
	$(this).addClass("active").siblings().removeClass("active")
	 myChart.setOption({ series:data1});
})

$(".line .cet").click(function(){
	$(this).addClass("active").siblings().removeClass("active")
	 myChart.setOption({ series:data2});
})

$(".line .rt").click(function(){
	$(this).addClass("active").siblings().removeClass("active")
	 myChart.setOption({ series:data3});
})
function show_content(){
    alert("暂无数据！");
}
function cancel(){
	$('#cancelModal').modal('hide');
	showLoading('退款中...');
	$.ajax( {
        url:'<?php echo site_url("gasstation/index/cancel")?>',
        data:{order_id:$('#cancel_order_id').val()},
        type:'post',
        cache:false,
        dataType:'json',    
        success:function(result) {
        	hideLoading();
        	if(result.ret == '200'){
            	if(result.data.code == '0'){
            		window.location.reload();
            	}else{
            		alert("退款失败:"+result.data.msg);
            	}
        		
			}else {
				alert("退款失败:"+result.msg);
			}
        },
        error : function() {
        	hideLoading();
			alert("error");
        }
	});
}
function cancelmodal(id){
	$("#cancel_order_id").val(id);
    $('#cancelModal').modal('show');
}
function socket() {
	var ip = 'ws://139.196.213.94:1212';
	var socket;
	socket = new WebSocket(ip);
    //连接建立
    socket.onopen = function(){
        send('order', 'get_order_oneday', {day: '2018-03-02',gasstation_id: '12'});
    };
    //收到消息
    socket.onmessage = function() {
   	 	var msg = JSON.parse(event.data); //解析收到的json消息数据
    };
    //发生错误
    socket.onerror = function(){
    
    };
    //连接关闭
    socket.onclose = function(){
    
    };

    function send(server, action, data){
        var msg = {
        	server: server,
        	action: action,
        	data: data
        };
        try{
            socket.send(JSON.stringify(msg));
        } catch(ex) {
        	
        }
    }
}
</script>